<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/*
<span class='line'>  2</span>  * Base class for all field validators
<span class='line'>  3</span>  *  
<span class='line'>  4</span>  * Copyright (C) 2011 Antti Leppä / Otavan Opisto
<span class='line'>  5</span>  * http://www.otavanopisto.fi
<span class='line'>  6</span>  * 
<span class='line'>  7</span>  * License: 
<span class='line'>  8</span>  * 
<span class='line'>  9</span>  * Licensed under GNU Lesser General Public License Version 3 or later (the "LGPL") 
<span class='line'> 10</span>  * http://www.gnu.org/licenses/lgpl.html
<span class='line'> 11</span>  */</span><span class="WHIT">
<span class='line'> 12</span> </span><span class="NAME">fi.internetix.validation.FieldValidator</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Class.create</span><span class="PUNC">(</span><span class="WHIT">
<span class='line'> 13</span> </span><span class="WHIT">  </span><span class="COMM">/** @lends fi.internetix.validation.FieldValidator# */</span><span class="WHIT"> 
<span class='line'> 14</span>   </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 15</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 16</span>   * Class constructor
<span class='line'> 17</span>   * @class Base class for all field validators
<span class='line'> 18</span>   * @constructs
<span class='line'> 19</span>   */</span><span class="WHIT">
<span class='line'> 20</span> </span><span class="WHIT">  </span><span class="NAME">initialize</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 21</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 22</span>    * Validates a field and returns it's status
<span class='line'> 23</span>    * 
<span class='line'> 24</span>    * @param field field to be validated
<span class='line'> 25</span>    * @returns 
<span class='line'> 26</span>    *   &lt;table>
<span class='line'> 27</span>    *     &lt;tr>
<span class='line'> 28</span>    *       &lt;td>fi.internetix.validation.FieldValidator#STATUS_UNKNOWN&lt;/td>&lt;td>&nbsp;&nbsp;If field cannot be validated&lt;/td>
<span class='line'> 29</span>    *     &lt;/tr>
<span class='line'> 30</span>    *     &lt;tr>
<span class='line'> 31</span>    *       &lt;td>fi.internetix.validation.FieldValidator#STATUS_VALID&lt;/td>&lt;td>&nbsp;&nbsp;If field is valid&lt;/td>
<span class='line'> 32</span>    *     &lt;/tr>
<span class='line'> 33</span>    *     &lt;tr>
<span class='line'> 34</span>    *       &lt;td>fi.internetix.validation.FieldValidator#STATUS_INVALID&lt;/td>&lt;td>&nbsp;&nbsp;If field is invalid&lt;/td>
<span class='line'> 35</span>    *     &lt;/tr>
<span class='line'> 36</span>    *   &lt;/table>
<span class='line'> 37</span>    */</span><span class="WHIT">
<span class='line'> 38</span> </span><span class="WHIT">  </span><span class="NAME">validate</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">field</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 39</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 40</span>    * Returns field type
<span class='line'> 41</span>    * 
<span class='line'> 42</span>    * @returns
<span class='line'> 43</span>    *   &lt;table>
<span class='line'> 44</span>    *     &lt;tr>
<span class='line'> 45</span>    *       &lt;td>fi.internetix.validation.FieldValidator.TYPE_NORMAL&lt;/td>&lt;td>&nbsp;&nbsp;For normal fields&lt;/td>
<span class='line'> 46</span>    *     &lt;/tr>
<span class='line'> 47</span>    *     &lt;tr>
<span class='line'> 48</span>    *       &lt;td>fi.internetix.validation.FieldValidator.TYPE_LINKED&lt;/td>&lt;td>&nbsp;&nbsp;For linked fields&lt;/td>
<span class='line'> 49</span>    *     &lt;/tr>
<span class='line'> 50</span>    *   &lt;/table>
<span class='line'> 51</span>    *   
<span class='line'> 52</span>    */</span><span class="WHIT">
<span class='line'> 53</span> </span><span class="WHIT">  </span><span class="NAME">getType</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 54</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 55</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 57</span>    * Returns class name of elements validator validates
<span class='line'> 58</span>    */</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT">  </span><span class="NAME">getClassName</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 62</span>    * @private   
<span class='line'> 63</span>    */</span><span class="WHIT">
<span class='line'> 64</span> </span><span class="WHIT">  </span><span class="NAME">_getFieldValue</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">field</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 65</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">field.type</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">'checkbox'</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 66</span> </span><span class="WHIT">      </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">field.checked</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="STRN">'0'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'1'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="WHIT">    </span><span class="KEYW">else</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="WHIT">      </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">field.value</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 69</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 70</span> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 71</span> 
<span class='line'> 72</span> </span><span class="COMM">/** @class **/</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="NAME">Object.extend</span><span class="PUNC">(</span><span class="NAME">fi.internetix.validation.FieldValidator</span><span class="PUNC">,</span><span class="WHIT"> 
<span class='line'> 74</span>   </span><span class="COMM">/** @lends fi.internetix.validation.FieldValidator# */</span><span class="WHIT">   
<span class='line'> 75</span>   </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 76</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 77</span>    * Invalid status
<span class='line'> 78</span>    */</span><span class="WHIT">
<span class='line'> 79</span> </span><span class="WHIT">  </span><span class="NAME">STATUS_UNDEFINED</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 80</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 81</span>    * Unknown status
<span class='line'> 82</span>    */</span><span class="WHIT">
<span class='line'> 83</span> </span><span class="WHIT">  </span><span class="NAME">STATUS_UNKNOWN</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 84</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 85</span>    * Invalid status
<span class='line'> 86</span>    */</span><span class="WHIT">
<span class='line'> 87</span> </span><span class="WHIT">  </span><span class="NAME">STATUS_INVALID</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 88</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 89</span>    * Valid status
<span class='line'> 90</span>    */</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT">  </span><span class="NAME">STATUS_VALID</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 93</span>    * Element is hidden and should be considered "valid".
<span class='line'> 94</span>    */</span><span class="WHIT">
<span class='line'> 95</span> </span><span class="WHIT">  </span><span class="NAME">STATUS_HIDDEN</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 96</span> 
<span class='line'> 97</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 98</span>    * Normal validator
<span class='line'> 99</span>    */</span><span class="WHIT">
<span class='line'>100</span> </span><span class="WHIT">  </span><span class="NAME">TYPE_NORMAL</span><span class="PUNC">:</span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>101</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>102</span>    * Mandatory validator
<span class='line'>103</span>    */</span><span class="WHIT">
<span class='line'>104</span> </span><span class="WHIT">  </span><span class="NAME">TYPE_MANDATORY</span><span class="PUNC">:</span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>105</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>106</span>    * Linked validator
<span class='line'>107</span>    */</span><span class="WHIT">
<span class='line'>108</span> </span><span class="WHIT">  </span><span class="NAME">TYPE_LINKED</span><span class="PUNC">:</span><span class="NUMB">2</span><span class="WHIT">    
<span class='line'>109</span> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span></pre></body></html>